package content;

import java.io.FileOutputStream;

import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;

import com.opensymphony.xwork2.ActionSupport;

public class OutputXml extends ActionSupport {

	private String filename;
	private String delfilename;
	private String index;
	private String viewtype;
	private FileOutputStream fos;

	public String execute() throws Exception {
		try {
			Element root = new Element("pageview");
			Element fiE = new Element("pageviewcontroller");
			fiE.setAttribute("id", String.valueOf("0"));
			fiE.setAttribute("parentid", String.valueOf("0"));
			fiE.setAttribute("type", String.valueOf(""));
			fiE.setAttribute("viewtype", String.valueOf(getViewtype()));
			fiE.setAttribute("tabindex", String.valueOf("ffffffff"));
			fiE.setAttribute("image", String.valueOf("0"));
			fiE.setAttribute("color", String.valueOf("#ffffffff"));
			fiE.setAttribute("navihide", String.valueOf("yes"));
			fiE.setAttribute("navibackgroundimage", String.valueOf(""));
			fiE.setAttribute("nabibackgroundcolor", String.valueOf(""));
			fiE.setAttribute("navitext", String.valueOf("test"));
			fiE.setAttribute("navitextcolor", String.valueOf(""));
			fiE.setAttribute("navitextshadowcolor", String.valueOf(""));
			fiE.setAttribute("navisize", String.valueOf("100"));
			fiE.setAttribute("navibackbutton", String.valueOf(""));
			fiE.setAttribute("navibackbuttonimage", String.valueOf(""));
			fiE.setAttribute("menubarshow", String.valueOf(""));
			fiE.setAttribute("subtabshow", String.valueOf("yes"));

			root.setContent(fiE);

			Document doc = new Document(root);

			XMLOutputter xmlOut = new XMLOutputter();
			Format format = Format.getPrettyFormat();
			xmlOut.setFormat(format);
			fos = new FileOutputStream("c:/" + getFilename() + ".xml");
			xmlOut.output(doc, fos);
			new InputXml(getFilename());
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			fos.close();
		}
		return SUCCESS;
	}

	public String del() throws Exception {

		new DelXml(getIndex(),getDelfilename());
		
		return SUCCESS;
	}

	public String getFilename() {
		return filename;
	}

	public void setFilename(String filename) {
		this.filename = filename;
	}

	public String getIndex() {
		return index;
	}

	public void setIndex(String index) {
		this.index = index;
	}

	public String getDelfilename() {
		return delfilename;
	}

	public void setDelfilename(String delfilename) {
		this.delfilename = delfilename;
	}

	public String getViewtype() {
		return viewtype;
	}

	public void setViewtype(String viewtype) {
		this.viewtype = viewtype;
	}
}
